package com.noahplat.user.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.user.pojo.Version;
import com.noahplat.user.service.VersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;

/**
 * 版本更新
 *
 * @author 李东
 * @version 1.0.0
 * @Date: 2021/5/8 8:38
 **/
@RequestMapping("/api/version")
@RestController
@Validated
public class VersionController {

    @Autowired
    private VersionService versionService;

    @GetMapping("/getVersionByStid")
    public Result getVersionByStid(@Min(value = 1, message = "系统Id不能为空") Long stid) {
        return versionService.getVersionByStid(stid);
    }

    /**
     * 添加版本
     *
     * @param version
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:VersionController:addVersion')")
    @PostMapping("/addVersion")
    public Result addVersion(@RequestBody Version version) {
        return versionService.addVersion(version);
    }

    /**
     * 分页获取版本
     *
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:VersionController:getVersion')")
    @GetMapping("/getVersion")
    public Result getVersion(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, String stid) {
        return versionService.getVersion(page, limit, stid);
    }

}
